package com.kfyty.loveqq.framework.boot.web.example.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.session.SaSession;
import cn.dev33.satoken.stp.StpUtil;
import com.kfyty.loveqq.framework.web.core.annotation.GetMapping;
import com.kfyty.loveqq.framework.web.core.annotation.RestController;

/**
 * 描述: sa-token 登录示例
 *
 * @author kfyty725
 * @date 2024/8/2 17:07
 * @email kfyty725@hotmail.com
 */
@RestController
public class LoginController {

    @GetMapping
    public String ignored() {
        return "ignored";
    }

    @SaIgnore
    @GetMapping
    public String ignored2() {
        return "ignored2";
    }

    @GetMapping
    @SaCheckLogin
    public String checkLogin() {
        return "check succeed";
    }

    @GetMapping
    public String isLogin() {
        return "当前会话是否登录：" + StpUtil.isLogin();
    }

    @GetMapping
    public String doLogin(String username, String password) {
        if("test".equals(username) && "123456".equals(password)) {
            StpUtil.login(10001);
            return "登录成功";
        }
        return "登录失败";
    }

    @GetMapping
    public SaSession logout() {
        SaSession session = StpUtil.getSession();
        StpUtil.logout();
        return session;
    }
}
